package manager
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;

	/**
	 * 公共数据 
	 * @author jp-077
	 * 
	 */	
	public class PublicData
	{
		
		public var selectXMLPath:String;
		
		
		private var _baseAPrice:Number;
		public function PublicData()
		{
			_instance = this;
			var fs1:FileStream = new FileStream();
			var baseXMLFile:File = new File(File.applicationStorageDirectory.resolvePath("baseXML.xml").nativePath);
			if(baseXMLFile.exists){
				
				fs1.open(baseXMLFile, FileMode.READ);
				_baseAPrice = Number(new XML(fs1.readUTFBytes(fs1.bytesAvailable)).price[0].@num);
				fs1.close();
			}else{
				fs1.open(baseXMLFile, FileMode.WRITE);
				var xml1:XML = <xml><price num = "20"/></xml>;
				fs1.writeUTFBytes(xml1.toXMLString());
				fs1.close();
				_baseAPrice = 20;
			}
		}
		
		public function set baseAprice(v:Number):void{
			if(v != _baseAPrice){
				// 改变默认的值
				// 写入xml
				var fs1:FileStream;
				var xml1:XML;
				var baseXMLFile:File = new File(File.applicationStorageDirectory.resolvePath("baseXML.xml").nativePath);
				if(baseXMLFile.exists){
					fs1 = new FileStream();
					fs1.open(baseXMLFile, FileMode.READ);
					xml1 = new XML(fs1.readUTFBytes(fs1.bytesAvailable));
					xml1.price[0].@num = v;
					fs1.close();
				}else{
					xml1 = new XML("<xml><price num = '" + v + "'/></xml>");
				}
				fs1 = new FileStream();
				fs1.open(baseXMLFile, FileMode.WRITE);
				fs1.writeUTFBytes(xml1.toXMLString());
				
				
				_baseAPrice = v;
			}
			
		}
		public function get baseAPrice():Number{
			return 	_baseAPrice;
		}
		
		
		
		private static var _instance:PublicData;
		public static function GetInstance():PublicData{
			if(! _instance) new PublicData();
			return _instance;
		}
	}
	
	
	
	
}